﻿using System;
using System.Web;
using System.Xml.Serialization;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint.Utilities;

namespace FTI.SP.LADM.EnhancedContentQueryWebPart
{
    public class EnhancedContentQueryToolPart :ToolPart
    {

        #region controls        
        CheckBox showToolbar;
        CheckBox showContextMenus;
        CheckBox showErrors;
        TextBox commonViewFields;
        TextBox dataSourcesString;
        TextBox itemXslLink;
        TextBox headerXslLink;
        TextBox mainXslLink;
        TextBox dataSourceID;
        TextBox queryOverride;
        CheckBox forceCheckout;
        Panel toolPanel;
        Table toolPanelTable;       
        // Fields
        private HtmlInputText commonViewFieldsTextBox;
        private EnhancedContentQueryWebPart cqwp;
        private HtmlInputText dataColumnRenamesTextBox;
        private HtmlInputText headerXslLinkTextBox;
        private HtmlInputText itemXslLinkTextBox;
        private HtmlInputText listsOverrideTextBox;
        private HtmlInputText mainXslLinkTextBox;
        private HtmlInputText pageSizeTextBox;
        private HtmlInputText pagingParameterNameTextBox;
        private HtmlGenericControl presentationSection;
        private HtmlInputText queryOverrideTextBox;
        private HtmlGenericControl querySection;
        #endregion

        // Methods
        private static void addToolPaneControl(Table sectionTable, string label, Control newControl)
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\">"));
            Label child = new Label();
            child.Text = SPHttpUtility.HtmlEncode(label);
            cell.Controls.Add(new LiteralControl("<b>"));
            cell.Controls.Add(child);
            cell.Controls.Add(new LiteralControl(":"));
            cell.Controls.Add(new LiteralControl("</b>"));
            cell.Controls.Add(new LiteralControl("</div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            cell.Controls.Add(newControl);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));
            cell.Controls.Add(new LiteralControl("<div style='width:100%' class='UserDottedLine'></div>"));
            row.Cells.Add(cell);
            sectionTable.Rows.Add(row);
        }

        public override void ApplyChanges()
        {
            base.ApplyChanges();
            int result = 0;
            if (!string.IsNullOrEmpty(this.pageSizeTextBox.Value) && !int.TryParse(this.pageSizeTextBox.Value, out result))
            {
                result = 0;
            }
            this.cqwp.CustomPageSize = result;
            string str = "p";
            if (!string.IsNullOrEmpty(this.pagingParameterNameTextBox.Value))
            {
                str = this.pagingParameterNameTextBox.Value;
            }
            this.cqwp.PagingParameterName = str;
            this.cqwp.ItemXslLink = this.itemXslLinkTextBox.Value;
            this.cqwp.HeaderXslLink = this.headerXslLinkTextBox.Value;
            this.cqwp.MainXslLink = this.mainXslLinkTextBox.Value;
            this.cqwp.QueryOverride = this.queryOverrideTextBox.Value;
            this.cqwp.ListsOverride = this.listsOverrideTextBox.Value;
            this.cqwp.CommonViewFields = this.commonViewFieldsTextBox.Value;
            this.cqwp.DataColumnRenames = this.dataColumnRenamesTextBox.Value;
            try
            {
                cqwp.ShowContextMenus = showContextMenus.Checked;
            }
            catch { }
            try
            {
                cqwp.ShowToolbar = showToolbar.Checked;
            }
            catch { }
            try
            {
                cqwp.ShowErrors = showErrors.Checked;
            }
            catch { }
            //try
            //{
            //    cqwp.CommonViewFields = commonViewFields.Text;
            //}
            //catch { }
            try
            {
                cqwp.DataSourcesString = dataSourcesString.Text;
            }
            catch { }
            //try
            //{
            //    cqwp.ItemXslLink = itemXslLink.Text;
            //}
            //catch { }
            //try
            //{
            //    cqwp.HeaderXslLink = headerXslLink.Text;
            //}
            //catch { }
            //try
            //{
            //    cqwp.MainXslLink = mainXslLink.Text;
            //}
            //catch { }
            try
            {
                cqwp.DataSourceID = dataSourceID.Text;
            }
            catch { }
            //try
            //{
            //    cqwp.QueryOverride = queryOverride.Text.Trim();
            //}
            //catch { }
        }

        protected override void CreateChildControls()
        {
            this.createControls();
            base.CreateChildControls();
        }

        private Control createColumnsGroup()
        {
            Table table2 = new Table();
            table2.ID = "columnsGroup";
            table2.Width = Unit.Percentage(100.0);
            Table table = table2;
            TableRow row = new TableRow();
            TableCell cell3 = new TableCell();
            cell3.VerticalAlign = VerticalAlign.Top;
            TableCell cell = cell3;
            HtmlInputText text = new HtmlInputText();
            text.ID = "ICBQToolPartCommonViewFieldsTextBox";
            this.commonViewFieldsTextBox = text;
            this.commonViewFieldsTextBox.Style.Add(HtmlTextWriterStyle.Width, "176px");
            this.commonViewFieldsTextBox.Attributes["class"] = "UserInput";
            this.commonViewFieldsTextBox.Attributes["onfocusin"] = BuilderButton.GetBuilderVisibilityFunctionCall(this.ClientID, this.commonViewFieldsTextBox.ID);
            this.commonViewFieldsTextBox.Attributes["ondeactivate"] = BuilderButton.GetDeactivateBuilderFunctionCall(this.ClientID, this.commonViewFieldsTextBox.ID);
            Panel child = new Panel();
            Label label3 = new Label();
            label3.Text = "Common View Fields:";
            label3.AssociatedControlID = this.commonViewFieldsTextBox.ID;
            Label label = label3;
            cell.Controls.Add(label);
            cell.Controls.Add(child);
            child.Controls.Add(this.commonViewFieldsTextBox);
            child.Controls.Add(new LiteralControl(BuilderButton.GetBuilderButtonMarkup(BuilderButton.DynamicBuilderButtons(this.Context.Request.Browser), this.ClientID, this.commonViewFieldsTextBox.ID, this.Context)));
            row.Cells.Add(cell);
            table.Rows.Add(row);
            TableRow row2 = new TableRow();
            TableCell cell4 = new TableCell();
            cell4.VerticalAlign = VerticalAlign.Top;
            TableCell cell2 = cell4;
            HtmlInputText text2 = new HtmlInputText();
            text2.ID = "ICBQToolPartDataColumnRenamesTextBox";
            this.dataColumnRenamesTextBox = text2;
            this.dataColumnRenamesTextBox.Style.Add(HtmlTextWriterStyle.Width, "176px");
            this.dataColumnRenamesTextBox.Attributes["class"] = "UserInput";
            this.dataColumnRenamesTextBox.Attributes["onfocusin"] = BuilderButton.GetBuilderVisibilityFunctionCall(this.ClientID, this.dataColumnRenamesTextBox.ID);
            this.dataColumnRenamesTextBox.Attributes["ondeactivate"] = BuilderButton.GetDeactivateBuilderFunctionCall(this.ClientID, this.dataColumnRenamesTextBox.ID);
            Panel panel2 = new Panel();
            Label label4 = new Label();
            label4.Text = "Data Column Renames:";
            label4.AssociatedControlID = this.dataColumnRenamesTextBox.ID;
            Label label2 = label4;
            cell2.Controls.Add(label2);
            cell2.Controls.Add(panel2);
            panel2.Controls.Add(this.dataColumnRenamesTextBox);
            panel2.Controls.Add(new LiteralControl(BuilderButton.GetBuilderButtonMarkup(BuilderButton.DynamicBuilderButtons(this.Context.Request.Browser), this.ClientID, this.dataColumnRenamesTextBox.ID, this.Context)));
            row2.Cells.Add(cell2);
            table.Rows.Add(row2);
            return table;
        }

        private void createControls()
        {
            Panel child = new Panel();
            child.CssClass = "ms-ToolPartSpacing";
            this.Controls.Add(child);
            this.createQuerySection();
            this.createPresentationSection();
            toolPanel = new Panel();
            toolPanel.CssClass = "ms-ToolPartSpacing";
            toolPanel.Controls.Add(GetToolPanel());
            this.Controls.Add(toolPanel);
        }

        private Control createPagingGroup()
        {
            Table table2 = new Table();
            table2.ID = "pagingGroup";
            table2.Width = Unit.Percentage(100.0);
            Table table = table2;
            TableRow row = new TableRow();
            TableCell cell3 = new TableCell();
            cell3.VerticalAlign = VerticalAlign.Top;
            TableCell cell = cell3;
            HtmlInputText text = new HtmlInputText();
            text.ID = "ICBQToolPartPageSizeTextBox";
            this.pageSizeTextBox = text;
            this.pageSizeTextBox.Attributes["class"] = "UserInput";
            this.pageSizeTextBox.Style.Add(HtmlTextWriterStyle.Width, "100%");
            Panel child = new Panel();
            Label label3 = new Label();
            label3.Text = "Page Size:";
            label3.AssociatedControlID = this.pageSizeTextBox.ID;
            Label label = label3;
            cell.Controls.Add(label);
            cell.Controls.Add(child);
            child.Controls.Add(this.pageSizeTextBox);
            row.Cells.Add(cell);
            table.Rows.Add(row);
            TableRow row2 = new TableRow();
            TableCell cell4 = new TableCell();
            cell4.VerticalAlign = VerticalAlign.Top;
            TableCell cell2 = cell4;
            HtmlInputText text2 = new HtmlInputText();
            text2.ID = "ICBQToolPartPagingParameterNameTextBox";
            this.pagingParameterNameTextBox = text2;
            this.pagingParameterNameTextBox.Attributes["class"] = "UserInput";
            this.pagingParameterNameTextBox.Style.Add(HtmlTextWriterStyle.Width, "100%");
            Panel panel2 = new Panel();
            Label label4 = new Label();
            label4.Text = "Paging Parameter Name:";
            label4.AssociatedControlID = this.pagingParameterNameTextBox.ID;
            Label label2 = label4;
            cell2.Controls.Add(label2);
            cell2.Controls.Add(panel2);
            panel2.Controls.Add(this.pagingParameterNameTextBox);
            row2.Cells.Add(cell2);
            table.Rows.Add(row2);
            return table;
        }

        private void createPresentationSection()
        {
            this.presentationSection = CmsDataFormWebPart.CreateToolPartToggleSwitch(this, "Expand Category: Presentation", "Collapse Category: Presentation", "Presentation", "ConfigurePresentation", null, true);
            Table sectionTable = new Table();
            sectionTable.CellPadding = 0;
            sectionTable.CellSpacing = 0;
            sectionTable.Style["border-collapse"] = "collapse";
            sectionTable.Attributes.Add("width", "100%");
            addToolPaneControl(sectionTable, "Paging", this.createPagingGroup());
            addToolPaneControl(sectionTable, "XSL", this.createXsltGroup());
            this.presentationSection.Controls.Add(sectionTable);
        }

        private Control createQueryGroup()
        {
            Table table2 = new Table();
            table2.ID = "queryGroup";
            table2.Width = Unit.Percentage(100.0);
            Table table = table2;
            TableRow row = new TableRow();
            TableCell cell3 = new TableCell();
            cell3.VerticalAlign = VerticalAlign.Top;
            TableCell cell = cell3;
            HtmlInputText text = new HtmlInputText();
            text.ID = "ICBQToolPartQueryOverrideTextBox";
            this.queryOverrideTextBox = text;
            this.queryOverrideTextBox.Style.Add(HtmlTextWriterStyle.Width, "176px");
            this.queryOverrideTextBox.Attributes["class"] = "UserInput";
            this.queryOverrideTextBox.Attributes["onfocusin"] = BuilderButton.GetBuilderVisibilityFunctionCall(this.ClientID, this.queryOverrideTextBox.ID);
            this.queryOverrideTextBox.Attributes["ondeactivate"] = BuilderButton.GetDeactivateBuilderFunctionCall(this.ClientID, this.queryOverrideTextBox.ID);
            Panel child = new Panel();
            Label label3 = new Label();
            label3.Text = "Query Override:";
            label3.AssociatedControlID = this.queryOverrideTextBox.ID;
            Label label = label3;
            cell.Controls.Add(label);
            cell.Controls.Add(child);
            child.Controls.Add(this.queryOverrideTextBox);
            child.Controls.Add(new LiteralControl(BuilderButton.GetBuilderButtonMarkup(BuilderButton.DynamicBuilderButtons(this.Context.Request.Browser), this.ClientID, this.queryOverrideTextBox.ID, this.Context)));
            row.Cells.Add(cell);
            table.Rows.Add(row);
            TableRow row2 = new TableRow();
            TableCell cell4 = new TableCell();
            cell4.VerticalAlign = VerticalAlign.Top;
            TableCell cell2 = cell4;
            HtmlInputText text2 = new HtmlInputText();
            text2.ID = "ICBQToolPartListsOverrideTextBox";
            this.listsOverrideTextBox = text2;
            this.listsOverrideTextBox.Style.Add(HtmlTextWriterStyle.Width, "176px");
            this.listsOverrideTextBox.Attributes["class"] = "UserInput";
            this.listsOverrideTextBox.Attributes["onfocusin"] = BuilderButton.GetBuilderVisibilityFunctionCall(this.ClientID, this.listsOverrideTextBox.ID);
            this.listsOverrideTextBox.Attributes["ondeactivate"] = BuilderButton.GetDeactivateBuilderFunctionCall(this.ClientID, this.listsOverrideTextBox.ID);
            Panel panel2 = new Panel();
            Label label4 = new Label();
            label4.Text = "Lists Override:";
            label4.AssociatedControlID = this.listsOverrideTextBox.ID;
            Label label2 = label4;
            cell2.Controls.Add(label2);
            cell2.Controls.Add(panel2);
            panel2.Controls.Add(this.listsOverrideTextBox);
            panel2.Controls.Add(new LiteralControl(BuilderButton.GetBuilderButtonMarkup(BuilderButton.DynamicBuilderButtons(this.Context.Request.Browser), this.ClientID, this.listsOverrideTextBox.ID, this.Context)));
            row2.Cells.Add(cell2);
            table.Rows.Add(row2);
            return table;
        }

        private void createQuerySection()
        {
            this.querySection = CmsDataFormWebPart.CreateToolPartToggleSwitch(this, "Expand Category: Query", "Collapse Category: Query", "Query", "ConfigureQuery", null, false);
            Table sectionTable = new Table();
            sectionTable.CellPadding = 0;
            sectionTable.CellSpacing = 0;
            sectionTable.Style["border-collapse"] = "collapse";
            sectionTable.Attributes.Add("width", "100%");
            addToolPaneControl(sectionTable, "Query", this.createQueryGroup());
            addToolPaneControl(sectionTable, "Columns", this.createColumnsGroup());
            this.querySection.Controls.Add(sectionTable);
        }

        private Control createXsltGroup()
        {
            Table table2 = new Table();
            table2.ID = "xsltGroup";
            table2.Width = Unit.Percentage(100.0);
            Table table = table2;
            TableRow row = new TableRow();
            TableCell cell4 = new TableCell();
            cell4.VerticalAlign = VerticalAlign.Top;
            TableCell cell = cell4;
            HtmlInputText text = new HtmlInputText();
            text.ID = "ICBQToolPartItemXslLinkTextBox";
            this.itemXslLinkTextBox = text;
            this.itemXslLinkTextBox.Style.Add(HtmlTextWriterStyle.Width, "176px");
            this.itemXslLinkTextBox.Attributes["class"] = "UserInput";
            this.itemXslLinkTextBox.Attributes["onfocusin"] = BuilderButton.GetBuilderVisibilityFunctionCall(this.ClientID, this.itemXslLinkTextBox.ID);
            this.itemXslLinkTextBox.Attributes["ondeactivate"] = BuilderButton.GetDeactivateBuilderFunctionCall(this.ClientID, this.itemXslLinkTextBox.ID);
            Panel child = new Panel();
            Label label4 = new Label();
            label4.Text = "Item XSL Link:";
            label4.AssociatedControlID = this.itemXslLinkTextBox.ID;
            Label label = label4;
            cell.Controls.Add(label);
            cell.Controls.Add(child);
            child.Controls.Add(this.itemXslLinkTextBox);
            child.Controls.Add(new LiteralControl(BuilderButton.GetBuilderButtonMarkup(BuilderButton.DynamicBuilderButtons(this.Context.Request.Browser), this.ClientID, this.itemXslLinkTextBox.ID, this.Context)));
            row.Cells.Add(cell);
            table.Rows.Add(row);
            TableRow row2 = new TableRow();
            TableCell cell5 = new TableCell();
            cell5.VerticalAlign = VerticalAlign.Top;
            TableCell cell2 = cell5;
            HtmlInputText text2 = new HtmlInputText();
            text2.ID = "ICBQToolPartHeaderXslLinkTextBox";
            this.headerXslLinkTextBox = text2;
            this.headerXslLinkTextBox.Style.Add(HtmlTextWriterStyle.Width, "176px");
            this.headerXslLinkTextBox.Attributes["class"] = "UserInput";
            this.headerXslLinkTextBox.Attributes["onfocusin"] = BuilderButton.GetBuilderVisibilityFunctionCall(this.ClientID, this.headerXslLinkTextBox.ID);
            this.headerXslLinkTextBox.Attributes["ondeactivate"] = BuilderButton.GetDeactivateBuilderFunctionCall(this.ClientID, this.headerXslLinkTextBox.ID);
            Panel panel2 = new Panel();
            Label label5 = new Label();
            label5.Text = "Header XSL Link:";
            label5.AssociatedControlID = this.headerXslLinkTextBox.ID;
            Label label2 = label5;
            cell2.Controls.Add(label2);
            cell2.Controls.Add(panel2);
            panel2.Controls.Add(this.headerXslLinkTextBox);
            panel2.Controls.Add(new LiteralControl(BuilderButton.GetBuilderButtonMarkup(BuilderButton.DynamicBuilderButtons(this.Context.Request.Browser), this.ClientID, this.headerXslLinkTextBox.ID, this.Context)));
            row2.Cells.Add(cell2);
            table.Rows.Add(row2);
            TableRow row3 = new TableRow();
            TableCell cell6 = new TableCell();
            cell6.VerticalAlign = VerticalAlign.Top;
            TableCell cell3 = cell6;
            HtmlInputText text3 = new HtmlInputText();
            text3.ID = "ICBQToolPartMainXslLinkTextBox";
            this.mainXslLinkTextBox = text3;
            this.mainXslLinkTextBox.Style.Add(HtmlTextWriterStyle.Width, "176px");
            this.mainXslLinkTextBox.Attributes["class"] = "UserInput";
            this.mainXslLinkTextBox.Attributes["onfocusin"] = BuilderButton.GetBuilderVisibilityFunctionCall(this.ClientID, this.mainXslLinkTextBox.ID);
            this.mainXslLinkTextBox.Attributes["ondeactivate"] = BuilderButton.GetDeactivateBuilderFunctionCall(this.ClientID, this.mainXslLinkTextBox.ID);
            Panel panel3 = new Panel();
            Label label6 = new Label();
            label6.Text = "Main XSL Link:";
            label6.AssociatedControlID = this.mainXslLinkTextBox.ID;
            Label label3 = label6;
            cell3.Controls.Add(label3);
            cell3.Controls.Add(panel3);
            panel3.Controls.Add(this.mainXslLinkTextBox);
            panel3.Controls.Add(new LiteralControl(BuilderButton.GetBuilderButtonMarkup(BuilderButton.DynamicBuilderButtons(this.Context.Request.Browser), this.ClientID, this.mainXslLinkTextBox.ID, this.Context)));
            row3.Cells.Add(cell3);
            table.Rows.Add(row3);
            return table;
        }

        protected override void OnInit(EventArgs e)
        {
            this.Title = "Enhanced Content Query Web Part";
            this.cqwp = base.ParentToolPane.SelectedWebPart as FTI.SP.LADM.EnhancedContentQueryWebPart.EnhancedContentQueryWebPart;
            if (this.cqwp == null)
            {
                throw new ContentByQueryWebPartException("Wrong Content Query Web Part");
            }
            base.OnInit(e);
        }

        protected override void OnPreRender(EventArgs e)
        {
            this.populateControls();
            base.OnPreRender(e);
        }

        private void populateControls()
        {
            this.pageSizeTextBox.Value = this.cqwp.CustomPageSize.ToString();
            this.pagingParameterNameTextBox.Value = this.cqwp.PagingParameterName;
            this.itemXslLinkTextBox.Value = this.cqwp.ItemXslLink;
            this.headerXslLinkTextBox.Value = this.cqwp.HeaderXslLink;
            this.mainXslLinkTextBox.Value = this.cqwp.MainXslLink;
            this.queryOverrideTextBox.Value = this.cqwp.QueryOverride;
            this.listsOverrideTextBox.Value = this.cqwp.ListsOverride;
            this.commonViewFieldsTextBox.Value = this.cqwp.CommonViewFields;
            this.dataColumnRenamesTextBox.Value = this.cqwp.DataColumnRenames;
        }
        #region ToolPanel building functions
        private Control GetToolPanel()
        {
            toolPanelTable = new Table();
            toolPanelTable.CellPadding = 0;
            toolPanelTable.CellSpacing = 0;
            //toolPanelTable.Style["border-collapse"] = "collapse";
            toolPanelTable.Attributes.Add("width", "100%");

            toolPanelTable.Rows.Add(GetShowContextMenusSettingsRow());
            toolPanelTable.Rows.Add(GetForceCheckoutSettingsRow());
            toolPanelTable.Rows.Add(GetCommonViewFieldsRow());
            toolPanelTable.Rows.Add(GetQueryOverrideStringRow());
            toolPanelTable.Rows.Add(GetDataSourcesStringRow());
            toolPanelTable.Rows.Add(GetDataSourceIDStringRow());
            toolPanelTable.Rows.Add(GetMainXslLinkRow());
            toolPanelTable.Rows.Add(GetItemXslLinkRow());
            toolPanelTable.Rows.Add(GetHeaderXslLinkRow());
            toolPanelTable.Rows.Add(GetSeperatorRow());
            toolPanelTable.Rows.Add(GetShowToolBarSettingsRow());
            toolPanelTable.Rows.Add(GetSeperatorRow());
            toolPanelTable.Rows.Add(GetDebuggingSettingsRow());
            toolPanelTable.Rows.Add(GetSeperatorRow());

            return toolPanelTable;
        }
        private TableRow GetShowContextMenusSettingsRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Context Menus Settings:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            showContextMenus = new CheckBox();
            showContextMenus.Checked = this.cqwp.ShowContextMenus;
            showContextMenus.Text = "Show Context Menus for Items?<br/>(Requires an xslt that can support it)";
            cell.Controls.Add(showContextMenus);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetForceCheckoutSettingsRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            forceCheckout = new CheckBox();
            forceCheckout.Checked = this.cqwp.ForceCheckout;
            forceCheckout.Text = "Force Checkout for Documents<br/>";
            cell.Controls.Add(forceCheckout);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetShowToolBarSettingsRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Tool Bar Settings:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            showToolbar = new CheckBox();
            showToolbar.Checked = this.cqwp.ShowToolbar;
            showToolbar.Text = "Show Tool Bar?<br/>(only in single document library mode)";
            cell.Controls.Add(showToolbar);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetDebuggingSettingsRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Debugging Settings:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            showErrors = new CheckBox();
            showErrors.Checked = this.cqwp.ShowErrors;
            showErrors.Text = "Show Errors?";
            cell.Controls.Add(showErrors);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetCommonViewFieldsRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Common View Fields:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            commonViewFields = new TextBox();
            if (!string.IsNullOrEmpty(this.cqwp.CommonViewFields))
            {
                commonViewFields.Text = this.cqwp.CommonViewFields;
            }
            else { commonViewFields.Text = ""; }

            cell.Controls.Add(commonViewFields);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetDataSourcesStringRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Data Source String:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            dataSourcesString = new TextBox();
            if (!string.IsNullOrEmpty(this.cqwp.DataSourcesString))
            {
                dataSourcesString.Text = this.cqwp.DataSourcesString;
            }
            else { dataSourcesString.Text = ""; }
            cell.Controls.Add(dataSourcesString);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetQueryOverrideStringRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Query Override:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            queryOverride = new TextBox();
            if (!string.IsNullOrEmpty(this.cqwp.QueryOverride))
            {
                queryOverride.Text = this.cqwp.QueryOverride;
            }
            else
            {
                queryOverride.Text = "";
            }
            cell.Controls.Add(queryOverride);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetDataSourceIDStringRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Data Source String:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            dataSourceID = new TextBox();
            if (!string.IsNullOrEmpty(this.cqwp.DataSourceID))
            {
                dataSourceID.Text = this.cqwp.DataSourceID;
            }
            else
            {
                dataSourceID.Text = "";
            }
            cell.Controls.Add(dataSourceID);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetItemXslLinkRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Item XSL Link:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            itemXslLink = new TextBox();
            if (!string.IsNullOrEmpty(this.cqwp.ItemXslLink))
            {
                itemXslLink.Text = this.cqwp.ItemXslLink;
            }
            else
            {
                itemXslLink.Text = "";
            }
            cell.Controls.Add(itemXslLink);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetHeaderXslLinkRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Header XSL Link:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            headerXslLink = new TextBox();
            if (!string.IsNullOrEmpty(this.cqwp.HeaderXslLink))
            {
                headerXslLink.Text = this.cqwp.HeaderXslLink;
            }
            else
            {
                headerXslLink.Text = "";
            }
            cell.Controls.Add(headerXslLink);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetMainXslLinkRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionHead\"><b>Main XSL Link:</b></div>"));
            cell.Controls.Add(new LiteralControl("<div class=\"UserSectionBody\"><div class=\"UserControlGroup\"><nobr>"));
            mainXslLink = new TextBox();
            if (!string.IsNullOrEmpty(this.cqwp.MainXslLink))
            {
                mainXslLink.Text = this.cqwp.MainXslLink;
            }
            else
            {
                mainXslLink.Text = "";
            }
            cell.Controls.Add(mainXslLink);
            cell.Controls.Add(new LiteralControl("</nobr></div></div>"));

            row.Cells.Add(cell);
            return row;
        }
        private TableRow GetSeperatorRow()
        {
            TableRow row = new TableRow();
            TableCell cell = new TableCell();
            cell.Controls.Add(new LiteralControl("<div style='width:100%' class='UserDottedLine'></div>"));
            row.Cells.Add(cell);
            return row;
        }
        #endregion
    }
}
